#include "cc_log.h"
#include "cc_core.h"
#include "cc_mempool.h"


#if (CC_CONFIG_TEST_MEM == 1)

cc_mempool_t mem;
int test_sem_create()
{
  mem = cc_mempool_create(10, MEM_BLOCK_REAL_SIZE(30));
  return 1;
}
CC_INIT_BOARD_REGISTER(test_sem_create);

void t1_mem(void* temp)
{
  char* data;
  while (1)
  {
    for (size_t i = 0; i < 10 + 10; i++)
    {
      data = (char*)cc_mempool_alloc_time(mem, 1000);
      cc_log("data:%p\r\n", data);
      if (data == CC_NULL)
      {
        cc_log_e("do not have enough mem\r\n");
        break;
      }
      sprintf((char*)data, "Hello:%d\r\n", i + 1);
      cc_log("%s", data);
      if (i < 5)
      {
        cc_mempool_free(mem, data);
      }
      cc_delay(100);
    }
    cc_log("success\r\n");
    break;
  }
}
CC_THREAD_REGISTER(t1_mem, 10, 2048);

#endif